package com.prjsystem.service.impl;


import java.util.List;

import com.prjsystem.common.constant.CMSConstant;
import com.prjsystem.common.util.CMSUtil;
import com.prjsystem.dao.CommonDao;
import com.prjsystem.dao.WorkRequestDetailDao;
import com.prjsystem.dao.WorkRequestViewDao;
import com.prjsystem.entity.WorkRequestDetail;
import com.prjsystem.entity.WorkRequestViewBean;
import com.prjsystem.service.WorkRequestService;

public class WorkRequestServiceImpl implements WorkRequestService{
	private WorkRequestViewDao workRequestViewDao;
	private WorkRequestDetailDao workRequestDetailDao;
	private CommonDao commonDao;
	private WorkRequestViewBean workRequestViewBean = new WorkRequestViewBean();
	private WorkRequestDetail workRequestDetail = new WorkRequestDetail();

	//对应 一览 和 检索按键
	public WorkRequestViewBean getWrView(WorkRequestViewBean workRequestViewBean) {
		workRequestViewBean.setAllwrList(workRequestViewDao.searchWrViewByWrid(workRequestViewBean));
		workRequestViewBean.setSelectListBean(commonDao.dropDowmList(CMSConstant.WR_DP_TYPE_SEARCH_LIST));
 		return workRequestViewBean;
	}
	//对应 Look and Edit 按键
	public WorkRequestViewBean getDetailWr(WorkRequestViewBean workRequestViewBean) {
		List<WorkRequestDetail> work = workRequestViewDao.searchWrAllByWrid(workRequestViewBean);
		if(work!=null&&work.size()>0){
			workRequestViewBean.setWorkRequestDetail(work.get(0));
		}
		workRequestViewBean.setSelectListBean(commonDao.dropDowmList(CMSConstant.WR_DP_TYPE_DETAIL_LIST));
		return workRequestViewBean;
	}
	//添加界面提取下拉菜单值
	public WorkRequestViewBean addDetailWr(WorkRequestViewBean workRequestViewBean) {
		workRequestDetail.setActualHour(CMSConstant.WorkRequestActuralHour);
		workRequestDetail.setPercentage(CMSConstant.WorkRequestPercentage);
		workRequestViewBean.setWorkRequestDetail(workRequestDetail);
		workRequestViewBean.setSelectListBean(commonDao.dropDowmList(CMSConstant.WR_DP_TYPE_DETAIL_LIST));
		return workRequestViewBean;
	}
	//对应删除案件
	public void deleteWr(WorkRequestViewBean workRequestViewBean) {
		workRequestViewDao.deleteById(workRequestViewBean);
	}
	//selectList
	public WorkRequestViewBean searchSelectList(WorkRequestViewBean workRequestViewBean) {
		workRequestViewBean.setSelectListBean(commonDao.dropDowmList(CMSConstant.WR_DP_TYPE_DETAIL_LIST));
		return workRequestViewBean;
	}
	//add and edit submit
	public void menuWr(WorkRequestViewBean workRequestViewBean) {
		if (!CMSUtil.isEmpty(workRequestViewBean.getWrId())) {
			workRequestDetailDao.updateWr(workRequestViewBean.getWorkRequestDetail());
		}
		else {
			workRequestDetailDao.addNewWr(workRequestViewBean.getWorkRequestDetail()); 
		}
	}
	
	public WorkRequestViewDao getWorkRequestViewDao() {
		return workRequestViewDao;
	}
	public void setWorkRequestViewDao(WorkRequestViewDao workRequestViewDao) {
		this.workRequestViewDao = workRequestViewDao;
	}
	public WorkRequestDetailDao getWorkRequestDetailDao() {
		return workRequestDetailDao;
	}
	public void setWorkRequestDetailDao(WorkRequestDetailDao workRequestDetailDao) {
		this.workRequestDetailDao = workRequestDetailDao;
	}
	public WorkRequestDetail getWorkRequestDetail() {
		return workRequestDetail;
	}
	public void setWorkRequestDetail(WorkRequestDetail workRequestDetail) {
		this.workRequestDetail = workRequestDetail;
	}
	public CommonDao getCommonDao() {
		return commonDao;
	}
	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}
	public void setWorkRequestViewBean(WorkRequestViewBean workRequestViewBean) {
		this.workRequestViewBean = workRequestViewBean;
	}
	public WorkRequestViewBean getWorkRequestViewBean() {
		return workRequestViewBean;
	}
}
